﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using WISD.CarFriend.BLL.Web;
using WISD.CarFriend.BLL.OA;

namespace WISD.CarFriend.Web.Admin.Module.UserManage
{
    public partial class UserAdd : Utility.BasicPage
    {
        private UserManageModule m_UserManageModuleBLL = new UserManageModule();
        private RoleManageModule m_RoleManageModuleBLL = new RoleManageModule();
        private ShopModule m_ShopModuleBLL = new ShopModule();

        /// <summary>
        /// Page_Load
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                if (!IsPostBack)
                {
                    // 验证权限
                    base.CheckPermission("UserManage_Add");

                    // 绑定角色下拉框
                    ddlRole.DataSource = this.m_RoleManageModuleBLL.GetList("1=1");
                    ddlRole.DataTextField = "UserRole";
                    ddlRole.DataValueField = "Id";
                    ddlRole.DataBind();

                    ddlShop.DataSource = this.m_ShopModuleBLL.GetList(" IsDel = 0 ");
                    ddlShop.DataTextField = "ShopName";
                    ddlShop.DataValueField = "Id";
                    ddlShop.DataBind();
                    ddlShop.Items.Insert(0, new ListItem("无", "-1"));
                }
            }
            catch (Exception exception)
            {
                base.ShowMessageBox(350, 230, "错误提示", "<b>出现错误啦！</b>" + exception.Message.ToString(), "back", "Error");
            }
        }


        /// <summary>
        /// 新增
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                WISD.CarFriend.Model.CFModel.T_CF_User userModel
                    = new Model.CFModel.T_CF_User();
                userModel.UserCode = txtUserCode.Text.Trim();
                userModel.Password = txtPassword.Text.Trim();
                userModel.UserName = txtUserName.Text.Trim();
                userModel.UserType = int.Parse(ddlRole.SelectedValue);
                userModel.IsLock = Boolean.Parse(rblIsLock.SelectedValue);
                userModel.ShopID = int.Parse(ddlShop.SelectedValue);
                userModel.CreatorID = int.Parse(Session["UserID"].ToString());
                userModel.CreateTime = DateTime.Now;
                userModel.UpdaterID = int.Parse(Session["UserID"].ToString());
                userModel.UpdateTime = DateTime.Now;
                this.m_UserManageModuleBLL.Add(userModel);
                ShowMessageBox("新增成功！", "UserList.aspx", "Success");
            }
            catch (Exception exception)
            {
                base.ShowMessageBox(350, 230, "错误提示", "<b>出现错误啦！</b>" + exception.Message.ToString(), "back", "Error");
            }
        }
    }
}